/** 
 * SaveDialog.java
 * @author Lex
 * 2007-9-1 ����11:47:58
 */
package org.lex.notepad.ui.filechooser;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Window;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class SaveDialog extends JDialog {
	private JPanel pane = null;
	private JFileChooser fileChooser = null;
	private JPanel controlPane = null;
	private JPanel charsetsPane = null;
	private JPanel buttonsPane = null;
	private JLabel charsetLabel = null;
	private JComboBox charsetsComboBox = null;
	private JButton okButton = null;
	private JButton cancelButton = null;

	public static void main(String[] args) {
		new SaveDialog(null).setVisible(true);
	}

	public SaveDialog(Window owner) {
		super(owner);
		initialize();
	}

	private void initialize() {
		this.setSize(500, 355);
		this.setContentPane(getPane());
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}

	private JPanel getPane() {
		if (pane == null) {
			pane = new JPanel();
			pane.setLayout(new BorderLayout());
			pane.add(getFileChooser(), BorderLayout.CENTER);
			pane.add(getControlPane(), BorderLayout.SOUTH);
		}
		return pane;
	}

	private JFileChooser getFileChooser() {
		if (null == fileChooser) {
			fileChooser = new JFileChooser();
			fileChooser.setControlButtonsAreShown(false);
		}
		return fileChooser;
	}

	private JPanel getControlPane() {
		if (controlPane == null) {
			controlPane = new JPanel();
			controlPane.setLayout(new BoxLayout(getControlPane(), BoxLayout.Y_AXIS));
			controlPane.add(getCharsetsPane(), null);
			controlPane.add(getButtonsPane(), null);
		}
		return controlPane;
	}

	private JPanel getCharsetsPane() {
		if (charsetsPane == null) {
			charsetLabel = new JLabel();
			charsetLabel.setText("Encoding :");
			charsetLabel.setBorder(new EmptyBorder(0, 0, 0, 12));
			charsetsPane = new JPanel(new BorderLayout());
			charsetsPane.setBorder(BorderFactory.createEmptyBorder(0, 12, 0, 12));
			charsetsPane.add(charsetLabel, BorderLayout.WEST);
			charsetsPane.add(getCharsetsComboBox(), BorderLayout.CENTER);
		}
		return charsetsPane;
	}

	private JPanel getButtonsPane() {
		if (buttonsPane == null) {
			FlowLayout flowLayout = new FlowLayout();
			flowLayout.setAlignment(FlowLayout.RIGHT);
			flowLayout.setVgap(11);
			flowLayout.setHgap(0);
			buttonsPane = new JPanel();
			buttonsPane.setLayout(flowLayout);
			buttonsPane.add(getOkButton());
			buttonsPane.add(Box.createHorizontalStrut(5));
			buttonsPane.add(getCancelButton());
			buttonsPane.add(Box.createHorizontalStrut(11));
		}
		return buttonsPane;
	}

	private JComboBox getCharsetsComboBox() {
		if (charsetsComboBox == null) {
			charsetsComboBox = new JComboBox();
		}
		return charsetsComboBox;
	}

	private JButton getOkButton() {
		if (okButton == null) {
			okButton = new JButton();
			okButton.setText("OK");
		}
		return okButton;
	}

	private JButton getCancelButton() {
		if (cancelButton == null) {
			cancelButton = new JButton();
			cancelButton.setText("Cancel");
		}
		return cancelButton;
	}
}
